package licode;

import java.util.ArrayList;

public class L35 {
    public static int searchInsert(int[] nums, int target) {
        int low = 0;
        int high = nums.length - 1;

        while (low <= high) {
            int mid = (low + high) / 2;
            if (nums[mid] == target) {
                return mid;
            }
            if (nums[mid] >target) {

                high = mid - 1;
            }
            if (nums[mid] <target) {
                low= mid + 1;
            }
        }

        return low;//这个才是要查找的元素
    }

    public static void main(String[] args) {
        int arr[]={1,3,5,6};
        int i = searchInsert(arr, 2);
        System.out.println(i);


    }


}
